package com.tlgen.orm.config;

import com.google.common.collect.Lists;
import com.tlgen.orm.components.dataSource.DataSourceContextHolder;
import com.tlgen.orm.utils.log.ColorLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.util.Collection;

@Configuration
public class OrmInitializer implements ApplicationRunner {

    @Autowired
    private DataSource dataSource;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        long startTime = System.currentTimeMillis();

        // ORM初始化逻辑
        // ...

        long endTime = System.currentTimeMillis();

        // 获取所有已注册的数据源信息
        Collection<DataSourceContextHolder.DataSourceInfo> dataSources =
                DataSourceContextHolder.getAllDataSourceInfos();

        // 打印炫酷启动日志（多数据源版本）
        ColorLogger.printMultiDataSourceBanner(
                "2.0",
                Lists.newArrayList(dataSources),
                endTime - startTime
        );

        ColorLogger.printSpeedOrmSuccessBanner("2.1.0", endTime - startTime);

    }

}